package com.wc.算法提高课.B第二章_搜索.最短路模型.抓住那头牛;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/9/23 18:40
 * @description https://www.acwing.com/problem/content/1102/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[] dist = new int[N];
    static int[] q = new int[N];
    static int n, k, res = N;

    public static void main(String[] args) {
        n = sc.nextInt();
        k = sc.nextInt();
        Arrays.fill(dist, -1);
        bfs();
        out.println(dist[k]);
        out.flush();
    }

    static void bfs() {
        if (n > k) {
            dist[k] = n - k;
            ;
            return;
        }
        int hh = 0, tt = 0;
        q[0] = n;
        dist[n] = 0;
        while (hh <= tt) {
            int t = q[hh++];
            // 表示下一步在牛的前面
            if (t * 2 < N && dist[t * 2] == -1) {
                dist[t * 2] = dist[t] + 1;
                q[++tt] = t * 2;
            }
            if (t + 1 < N && dist[t + 1] == -1) {
                dist[t + 1] = dist[t] + 1;
                q[++tt] = t + 1;
            }
            if (t - 1 > 0 && dist[t - 1] == -1) {
                q[++tt] = t - 1;
                dist[t - 1] = dist[t] + 1;
            }
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
